<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Cafe extends Model
{
    //
    protected $guarded = [];

    public function brewMethods(){
        return $this->belongsToMany(BrewMethod::class,'cafes_brew_methods','cafe_id','brew_method_id');
    }

    public function parent(){
        return $this->belongsTo(Cafe::class,'id','parent_id');
    }

    public function children(){
        return $this->hasMany(Cafe::class,'parent_id','id');
    }

    /**
     * Created by zengwei.
     * Date: 2019/10/15
     * Time: 10:14
     * Function:喜欢cafe店的用户
     * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
     *
     */
    public function likes(){
        return $this->belongsToMany(User::class,'users_cafes_likes','cafe_id','user_id');
    }

    /**
     * Created by zengwei.
     * Date: 2019/10/15
     * Time: 16:05
     * Function:
     * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
     *
     */
    public function tags(){
        return $this->belongsToMany(Tag::class,'cafes_users_tags','cafe_id','tag_id');
    }

    public function photos(){
        return $this->hasMany(CafesPhoto::class,'cafe_id','id');
    }

    public function company(){
        return $this->belongsTo(Company::class,'company_id','id');
    }
}
